<?php
namespace Admin\Model;

use Think\Model;

class TimetableModel extends Model {


    public function _add($data) {
        $map['week'] = $data['week'];
        $map['xq'] = $data['xq'];
        $map['end'] = array('GT',$data['start']);
        $map['teachplan_id'] = $data['teachplan_id'];

        $res = $this->where($map)->find();
        if (!empty($res)) return '101201';

        $flag = $this->add($data);
        if ($flag !== false) return '000000';
        return '111111';
    }

    // 根据教学计划ID,获取该计划下得所有课表信息
    public function getTimetableByTid($tid) {
        $map['teachplan_id'] = $tid;
        return $this->where($map)->order('week asc,xq asc,start asc')->select();
    }


    /**
     * 根据教学计划id,删除所有课表
     *
     * @param $tid
     * @return string
     */
    public function delTimetableByTid($tid) {
        $map['teachplan_id'] = $tid;
        $flag = $this->where($map)->delete();
        if ($flag !== false) return '000000';
        return '111111';
    }


}